package cn.schoolwow.util.module.query.jsonarray.flow.filter;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.module.query.jsonarray.domain.JSONArrayQueryOption;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class SetFilterJSONArrayFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        JSONArrayQueryOption jsonQueryOption = flowContext.checkInstanceData(JSONArrayQueryOption.class);

        if(null==jsonQueryOption.array){
            flowContext.brokenCurrentFlow("列表为空");
        }
        JSONArray filterArray = new JSONArray();
        for(int i=0;i<jsonQueryOption.array.size();i++){
            JSONObject object = jsonQueryOption.array.getJSONObject(i);
            filterArray.add(object);
        }
        flowContext.putTemporaryData("filterArray", filterArray);
    }

    @Override
    public String name() {
        return "设置过滤JSON数组";
    }
}
